<?php

//DEBUG_START_TIME
$stimer = explode( ' ', microtime() );
$stimer = $stimer[1] + $stimer[0];
//DEBUG_END_TIME

require_once 'tpl/use/Posting.php';
require_once 'util/smurfs.php';

switch( $_REQUEST['type'] ) {
  case 'EDIT':
    handlePostEdit(); break;
  case 'NEW':
  default:
    handleNewPost(); break;
}

//DEBUG_START_TIME
$etimer = explode( ' ', microtime() );
$etimer = $etimer[1] + $etimer[0];
echo '<p style="margin:auto; text-align:center">';
printf( "Script timer: <b>%f</b> seconds.", ($etimer-$stimer) );
echo '</p>';
//DEBUG_END_TIME

function handlePostEdit() {
  require 'db/get/post.php';

  if ( $_REQUEST['pnum'] < 1 && $_REQUEST['tnum'] < 1 ) {
    die( "breakage" ); // breakage
  }
  $post = getPost((int)intval($_REQUEST['tnum']), (int)intval($_REQUEST['pnum']));

  $post['datum'] = unsmurf($post['datum'], $post['smurfKey']);

  require 'tpl/use/EditPost.php';
  skin_EditPost( $post );
}

function handleNewPost() {
  
  require 'tpl/use/NewPost.php';
  skin_NewPost( (int)intval($_REQUEST['fnum']), (int)intval($_REQUEST['tnum']) );
}

?>
